
package action;

import db.Forum;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.Before;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.controller.LifecycleStage;

/**
 * Show one forum.
 * @author Tomas CASTA
 */
@UrlBinding("/forum.action")
public class ShowForumActionBean implements ActionBean {
    /* action context */
    private ActionBeanContext context;
    /* forum */
    private Forum forum;
    /* error message */
    private String errMsg;
    /* show forum? */
    private boolean show;
    
    public boolean isShow() {
        return show;
    }

    public void setShow(boolean show) {
        this.show = show;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public Forum getForum() {
        return forum;
    }

    public void setForum(Forum forum) {
        this.forum = forum;
    }
    

    public ActionBeanContext getContext() {
        return context;
    }

    public void setContext(ActionBeanContext context) {
        this.context = context;
    }

    /**
     * Show forum.
     * @return Resolution.
     */
 
    @DefaultHandler
    public Resolution show() {
        forum = new Forum();
        boolean isDb = forum.setDb(context.getServletContext());
        show = false;
        try {
            /* Parse forum id from URI */
            int idValue = Integer.valueOf(context.getRequest().getParameter("id"));

            /* Show forum by given id */
            forum.showForumById(idValue);
            show = true;
            return new ForwardResolution("jsp/forum.jsp");
        } catch (NumberFormatException e) {
            Logger.getLogger(DeleteMessageActionBean.class.getName()).log(Level.SEVERE, null, e);
            return new ForwardResolution("/index.action");
        }
    }
}
